package com.fenghongzhang.day004;

import android.os.Bundle;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private RadioGroup group;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
         group = findViewById(R.id.group);

         //选择改变监听
         group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
             /**
              *
              * @param group
              * @param checkedId 单选radioButton的id
              */
             @Override
             public void onCheckedChanged(RadioGroup group, int checkedId) {
//                switch (checkedId){
//                    case R.id.windows:
//                        Toast.makeText(MainActivity.this, "wind", Toast.LENGTH_SHORT).show();
//                        break;
//                    case R.id.ios:
//                        Toast.makeText(MainActivity.this, "ios", Toast.LENGTH_SHORT).show();
//                        break;
//                }

                 //2
                 RadioButton radioButton = findViewById(checkedId);
//                 radioButton.setTextColor();
                 String string = radioButton.getText().toString();
                 Toast.makeText(MainActivity.this, string, Toast.LENGTH_SHORT).show();
             }
         });
    }
}
